package com.java2007.dao.impl;

import com.java2007.dao.OrderDetailDao;
import com.java2007.pojo.OrderDetail;
import com.java2007.util.JdbcUtil;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
 * 订单详情持久层
 */
public class OrderDetailDaoImpl implements OrderDetailDao {
    /**
     * 储存订单详情
     * @param orderDetail
     * @return
     */
    @Override
    public int insert(OrderDetail orderDetail) throws SQLException {
        QueryRunner qr=new QueryRunner();
        String sql="INSERT INTO t_order_detail " +
                "(id,food_id,food_name,food_price,num,total_price,create_time,update_time,order_id) " +
                "VALUES (?,?,?,?,?,?,?,?,?)";
        return qr.update(JdbcUtil.getConnection(),sql,orderDetail.getId(),orderDetail.getFoodId(),orderDetail.getFoodName(),orderDetail.getFoodPrice(),orderDetail.getNum(),orderDetail.getTotalPrice(), orderDetail.getCreateTime(), orderDetail.getUpdateTime(),orderDetail.getOrderId());
    }
}
